package persist

import (
	"sync"
)

type Connect struct {
	*config
	IxDriver
	once sync.Once
}

// InitConnect 初始化数据库连接
func (conn *Connect) InitConnect(driver IxDriver, cfgName string) *Connect {
	conn.config = new(config).readConfig(cfgName)
	conn.once.Do(func() {
		conn.IxDriver = driver.openConn(conn.config)
	})
	return conn
}

// ReleaseConnect 初始化数据库连接
func (conn *Connect) ReleaseConnect() error {
	return conn.IxDriver.closeConn()
}
